package com.wd.amodel;

import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;

import com.wd.amodel.bean.Barrage;
import com.wd.amodel.fragment.DemoFragment;
import com.wd.amodel.view.NoticeInfoView;
import com.wd.annotation.Route;
import com.wd.base.config.Constance;
import com.wd.base.util.TextUtils;
import com.wd.common.eventbus.LbSubscribe;
import com.wd.common.eventbus.LbSubscribeThreadMode;

/**
 * NA<BR>
 *
 * @author w4425
 * @version [V2.0.0, 2021/4/20]
 * @since V2.0.0
 */
@Route(path = Constance.MODULE_URL_DEMO_A)
public class DemoActivity extends FragmentActivity {
    private FrameLayout frameLayout;
    private Button btnDanmaku;
    private NoticeInfoView noticeView = null;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo);
        initView();

        initData();
//        getTaskView();
    }

    private void initData() {

    }

    int count = 0;

    private void initView() {
        frameLayout = findViewById(R.id.layout_item);
        btnDanmaku = findViewById(R.id.btn_danmaku);

        btnDanmaku.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (noticeView == null) {
                    noticeView = new NoticeInfoView(DemoActivity.this, null);
                }
                String msg = "";
                String msg1 = "{\n" +
                        "        \"linkMsg\":\"\",\n" +
                        "        \"msgTitle\":\"测试公告啊测试公告十测试公告啊测试公二十测试公二五测试公告啊\",\n" +
                        "        \"name\":\"sj测试\",\n" +
                        "        \"presenterId\":\"b388a54a77574783b0f4859c40219346\",\n" +
                        "        \"createDate\":1623133547438,\n" +
                        "        \"urlPathLarge\":\"\",\n" +
                        "        \"urlPathSmall\":\"\",\n" +
                        "        \"type\":\"5\",\n" +
                        "        \"msgImg\":\"\",\n" +
                        "        \"portraitUrl\":\"http://img.cmvideo.cn:8080/publish/noms_wc/2019/03/13/5910MJI8G3I8.png\",\n" +
                        "        \"flag\":\"1\",\n" +
                        "        \"linkMsgUrl\":\"\",\n" +
                        "        \"isTop\":\"0\",\n" +
                        "        \"isTopic\":\"0\",\n" +
                        "        \"msg\":\"https://huaban.com/all/\",\n" +
                        "        \"msgId\":\"2021060814254785\",\n" +
                        "        \"msgSubType\":\"1\"\n" +
                        "    }";
                String msg2 = "{\n" +
                        "        \"linkMsg\":\"\",\n" +
                        "        \"msgTitle\":\"测试公告啊测试公\",\n" +
                        "        \"name\":\"sj测试\",\n" +
                        "        \"presenterId\":\"b388a54a77574783b0f4859c40219346\",\n" +
                        "        \"createDate\":1623133547438,\n" +
                        "        \"urlPathLarge\":\"\",\n" +
                        "        \"urlPathSmall\":\"\",\n" +
                        "        \"type\":\"5\",\n" +
                        "        \"msgImg\":\"\",\n" +
                        "        \"portraitUrl\":\"http://img.cmvideo.cn:8080/publish/noms_wc/2019/03/13/5910MJI8G3I8.png\",\n" +
                        "        \"flag\":\"1\",\n" +
                        "        \"linkMsgUrl\":\"\",\n" +
                        "        \"isTop\":\"0\",\n" +
                        "        \"isTopic\":\"0\",\n" +
                        "        \"msg\":\"\",\n" +
                        "        \"msgId\":\"2021060814254785\",\n" +
                        "        \"msgSubType\":\"1\"\n" +
                        "    }";
                if (count % 2 == 0) {
                    msg = msg1;
                } else {
                    msg = msg2;
                }
                noticeView.init(true, Configuration.ORIENTATION_PORTRAIT, msg, frameLayout);
                count++;

            }
        });
    }


    private void loadFragment(Bundle savedInstanceState) {
        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction().replace(R.id.container, DemoFragment.newInstance()).commitNow();
        }
    }

    private void loadString() {
        TextView tv_text = findViewById(R.id.tv_text);
//        String string = "我是字符串我是字符串";
//        String string = "我是字符串我是字符串我是字符串";
        String string = "我是字符串我是字符串ABCDEF";
//        String string = "ABCD我是字符串我是字符串串";
        string = TextUtils.handleText(string, 24);
        tv_text.setText(string);

        View indicator = findViewById(R.id.view_indicator);
        GradientDrawable drawable = new GradientDrawable();
        drawable.setColor(true ? Color.parseColor("#00ACFF") : Color.parseColor("#808080"));
        indicator.setBackground(drawable);
        indicator.getLayoutParams().width = 60;
    }


    /**
     * 倒计时
     */
    private void getTaskView() {
        CountDownTimer cdTimer = new CountDownTimer(900000, 3000) {
            @Override
            public void onTick(long millisUntilFinished) {
            }

            @Override
            public void onFinish() {

            }

        };
        cdTimer.start();

    }

    @LbSubscribe(THREAD_MODE = LbSubscribeThreadMode.MAIN)
    public void receive(String event) {
        if (event != null) {
            /* Additional fields if needed */
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
